package com.t1.demo.Share;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * @Description:Swing窗体
 * @Author: 杨淮尊
 * @Date: 2020/4/13
 **/
public class BorderInit extends JFrame {
    //序列号
    private static final long serialVersionUID = 1L;
    //Swing组件
    public JLabel jlbImg;
    //标识
    private boolean flag;
    public boolean getFlag(){
        return this.flag;
    }
    //构造
    public BorderInit(String IP,Integer SERVERPORT)
    {
        this.flag=true;
        this.jlbImg = new JLabel();
        //设置Swing标题
        this.setTitle("桌面共享-IP:"+IP+"-PORT:"+SERVERPORT);
        //设置Swing大小
        this.setSize(400, 400);
        //this.setUndecorated(true);  //全屏显示，测试时最好注释掉
        //this.setAlwaysOnTop(true);  //显示窗口始终在最前面
        //添加组件到结尾
        this.add(jlbImg);
        //设置窗口相对于指定组件的位置 null为正中央
        this.setLocationRelativeTo(null);
        //设置窗体扩展状态
        this.setExtendedState(Frame.MAXIMIZED_BOTH);
        //设置默认退出按钮
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        //开始执行
        this.setVisible(true);
        //校验组件
        this.validate();
        //窗口关闭事件
        this.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                flag=false;
                BorderInit.this.dispose();
                System.out.println("窗体关闭");
                System.gc();    //垃圾回收
            }
        });
    }
}
